<?php
/**
 * Created by PhpStorm.
 * User: guanfangge
 * Date: 4/28/22
 * Time: 9:48 AM
 */
namespace App\Utility;

use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\EasySwoole\Logger;
use EasySwoole\Log\LoggerInterface;
use EasySwoole\RabbitMq\MqJob;
use EasySwoole\RabbitMq\MqQueue;


class RabitMqQueue extends AbstractProcess {

    protected function run($arg)
    {
        // TODO: Implement run() method.
        go(function(){
            $MqQueue = MqQueue::getInstance()->refreshConnect();
            $MqQueue->consumer()->setConfig($exchange = 'test_topic_ex', $routingKey = 'com.#',$mqType = 'topic', $queueName = 'topic_hello')->listen(function(MqJob $obj) {
                echo " [x] Received ", $obj->getJobData(), "\n";
                Logger::getInstance()->log('log level info' . var_export($obj->getJobData(), true), LoggerInterface::LOG_LEVEL_INFO, 'DEBUG');//记录info级别日志//例子后面2个参数默认值
                //return;   //使用return 终止执行下面的代码
                //$obj->setWaitConfirmTime(time());
                  return true;   //使用return true终止执行下面的代码
               // echo 11111;
                //return false;  //return false消息回滚,所以请注意，不要随意使用return false
            });


        });
    }
}